import requests
import redis
import random


def save_request_url(url):
    client = redis.Redis()
    client.lpush("request_url", url)
    client.close()


def change_url(url):
    client = redis.Redis()
    urls = client.lrange("request_url", 0, -1)
    client.close()
    return url.encode() in urls


def main():
    urls = [f"https://httpbin.org/get?a={random.randint(1,100)}" for i in range(10)]
    urls = set(urls)
    for url in urls:
        if not change_url(url):
            res = requests.get(url)
            print(res)
            save_request_url(url)
        else:
            print("已经爬过了")


main()
